import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:ls_work/message/message_config.dart';
import 'package:ls_work/net/post_request.dart';
import 'package:ls_work/net/response/response_data.dart';
import 'package:ls_work/net/response/service_order_list_data.dart';

class ServiceOrderListViewModel extends BaseListViewModel<ServiceOrderListData>{
  final String statusId;
  ServiceOrderListViewModel(BuildContext context,this.statusId) : super(context);

  @override
  Future<List<ServiceOrderListData>> requestListData() async {
    var data = await PostRequest.serviceOrderList(statusId, page, pageLength,pcOrApp: 1);
    var bean = ResponseData.fromJson(data,listBuilder: (i)=>ServiceOrderListData.fromJson(i));
    if("0"==bean.code){
      return bean.data?.rows??[];
    }else{
      throw bean.msg??"";
    }
  }

  @override
  void onCreated() {
    super.onCreated();
    requestRefresh();
  }

  @override
  void receiveMessage(SendMessageEvent event) {
    super.receiveMessage(event);
    if(event.msgCode==MessageConfig.REFRESH_ORDER){
      requestRefresh();
    }
  }
}